package model.trader;



import java.util.ArrayList;
import java.util.List;

import model.market.MarketInformation;
import model.market.MarketManager;
import model.market.Position;
import model.market.Trade;

//AMLOW: comments..
public class MarketMaker implements Trader{

	private int tradeValue = 100000;
	int positionOpenDays=0;
	//int posLimitDays = 5;
	double shiftRequiredToTrade=.2;
	//double desiredProfitOrStopLoss=.2;
	
	
	public MarketMaker(){}
	
	public MarketMaker(double shiftRequiredToTrade){
		this.shiftRequiredToTrade=shiftRequiredToTrade;
		
	}
	
	public MarketMaker(double shiftRequiredToTrade,int tradeValue){
		this.shiftRequiredToTrade=shiftRequiredToTrade;
		this.tradeValue=tradeValue;
	}
	
	public List<Trade> trade(MarketManager market, Position position,MarketInformation info) {
		
		List<Trade> ret = new ArrayList<Trade>();
		//AMLOW: convert to real market maker, look to offload inventory, 
		// therefore dont always hit evenly either side of the current price. (and liquidity shouldnt increase with price?? or should it!.
		
		for(int assetCount=0;assetCount<info.getNumberOfAssets();assetCount++){
			//100);//AMNM: temp maybe we want to adjust for market cap.
			int tradeQuantity = (int)((tradeValue)/info.getMarketPrices()[assetCount]);
			
			int executedQuantity = position.getExecutedQuantity(assetCount);
			//if theres a trade open, manage that..
			if(executedQuantity!=0){
				
				
				//We have a trade running!!
				//AMNM: possibly temp, never close positions 
	//			market.closeOrder(position);
	//			int quantity = executedQuantity;
	//			boolean direction = Trade.SELL;
	//			if(quantity<0){
	//				direction=Trade.BUY;
	//			}
	//			Trade last = position.getExecutedTrades().get(position.getExecutedTrades().size()-1);
	//			Trade cancel = new Trade(this,quantity,direction,last.getExecutedPrice());
	//			market.order(cancel);	
				
				//AM: let them trade again today (even though it doesnt really make sense!)... return;
			}
			//AMLOW: temp possibly.. ive made it harder to sell...
			ret.add(
					new Trade(this,
							assetCount,
							(int)(tradeQuantity*.8),
							info.getMarketPrices()[assetCount]*(1/(1+shiftRequiredToTrade))));
			
			
			ret.add(
					new Trade(this,
							assetCount,
							-(int)(tradeQuantity),
							info.getMarketPrices()[assetCount]*(1+shiftRequiredToTrade)));
		
		}
		return ret;
	}
	
	public double getShiftRequiredToTrade() {
		return shiftRequiredToTrade;
	}

	public void setShiftRequiredToTrade(double shiftRequiredToTrade) {
		this.shiftRequiredToTrade = shiftRequiredToTrade;
	}

	public int getTradeValue() {
		return tradeValue;
	}

	public void setTradeValue(int tradeValue) {
		this.tradeValue = tradeValue;
	}
	
	
//	AM: shitty code.
	private int startPeriod;
	public int getStartPeriod() {
		return startPeriod;
	}

	public void setStartPeriod(int period) {
		this.startPeriod=period;
	}


}
